package cn.drenal.capcap.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.drenal.capcap.common.Response;
import cn.drenal.capcap.entity.SysAdminRole;
import cn.drenal.capcap.entity.dto.AdminRoleDTO;
import cn.drenal.capcap.service.SysAdminRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户角色管理控制器
 */
@RestController
@RequestMapping("/admin-role")
@RequiredArgsConstructor
public class SysAdminRoleController {

    private final SysAdminRoleService sysAdminRoleService;

    /**
     * 分配用户角色
     *
     * @param adminRoleDTO 用户角色信息
     * @return 分配结果
     */
    @PostMapping
    @SaCheckPermission("system:admin:role")
    public Response<Void> assignAdminRole(@RequestBody AdminRoleDTO adminRoleDTO) {
        sysAdminRoleService.assignAdminRole(adminRoleDTO);
        return Response.success();
    }

    /**
     * 获取用户角色ID列表
     *
     * @param userId 用户ID
     * @return 角色ID列表
     */
    @GetMapping("/user/{userId}")
    @SaCheckPermission("system:admin:query")
    public Response<List<Long>> getAdminRoles(@PathVariable Long userId) {
        return Response.success(sysAdminRoleService.getAdminRoleIds(userId));
    }
}